@extends('home.wechat.layouts.app')
@section('content')
    <div class="page-address-list" data-log="地址列表">

        @include('home.wechat.layouts._header')
        <div class="address-choose">

            <ul class="ui-list">
                @foreach($address as $ad)
                <li class="ui-list-item" data-id="{{$ad->id}}"><p class="ui_fz30"><span class="consignee">{{$ad->name}}</span><span>{{$ad->tel}}</span>
                    </p>
                    <p>{{$ad->province}} {{$ad->city}} {{$ad->area}}</p>
                    <p>{{$ad->detail}}</p></li>
                @endforeach
            </ul>

        </div>
        <div class="add"><a href="{{route('wechat.address.create')}}" class="ui-button ui-button-active"><span>新建地址</span></a></div>
        <div class="popup-risk-check"></div>
    </div>
    @endsection

@section('js')
    <script>
        $(function () {
            $("li").click(function () {
                var address_id = $(this).data("id");
//                console.log(address_id);return;
                $.ajax({
                    type: "PATCH",
                    url: "/wechat/address/default_address",
                    data: {address_id: address_id},
                    success: function (data) {
//                        console.log(data);
                        location.href = '/wechat/order/checkout';
                    }
                })
            })
        })
    </script>
@endsection